Passed
Push — develop ( 34c641...3cd61b )
by Andrew
03:13
created

index.d.ts ➔ PluginCritical   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
interface PenthouseConfig {
2
    /** Accessible url. Use file:/// protocol for local html files. */
3
    url: string;
4
    /** Original css to extract critical css from */
5
    cssString: string;
6
    /** Path to original css file on disk (if using instead of `cssString`) */
7
    css: string;
8
    /** Width for critical viewport */
9
    width: number;
10
    /** Height for critical viewport */
11
    height: number;
12
    /** Configuration for screenshots (not used by default). See [Screenshot example](https://github.com/pocketjoso/penthouse/blob/master/examples/screenshots.js) */
13
    screenshots: object;
14
    /** Keep media queries even for width/height values larger than critical viewport. */
15
    keepLargerMediaQueries: boolean;
16
    /**
17
     * Array of css selectors to keep in critical css, even if not appearing in critical viewport.
18
     * Strings or regex (f.e. `['.keepMeEvenIfNotSeenInDom', /^\.button/]`)
19
     */
20
    forceInclude: Array<string>;
21
    /**
22
     * Array of css selectors to remove in critical css, even if appearing in critical viewport.
23
     * Strings or regex (f.e. `['.doNotKeepMeEvenIfNotSeenInDom', /^\.button/]`)
24
     */
25
    forceExclude: Array<string>;
26
    /** Css properties to filter out from critical css */
27
    propertiesToRemove: Array<string>;
28
    /** Ms; abort critical CSS generation after this time */
29
    timeout: number;
30
    /** Settings for puppeteer. See [Custom puppeteer browser example](https://github.com/pocketjoso/penthouse/blob/master/examples/custom-browser.js) */
31
    puppeteer: object;
32
    /** Ms; stop waiting for page load after this time (for sites when page load event is unreliable) */
33
    pageLoadSkipTimeout: number;
34
    /**
35
     * ms; wait time after page load before critical css extraction starts
36
     * (also before "before" screenshot is taken, if used)
37
     */
38
    renderWaitTime: number;
39
    /** set to false to load JS (not recommended) */
40
    blockJSRequests: boolean;
41
    /** characters; strip out inline base64 encoded resources larger than this */
42
    maxEmbeddedBase64Length: number;
43
    /** Can be specified to limit nr of elements to inspect per css selector, reducing execution time. */
44
    maxElementsToCheckPerSelector: number;
45
    /** specify which user agent string when loading the page */
46
    userAgent: string;
47
    /** Set extra http headers to be sent with the request for the url. */
48
    customPageHeaders: object;
49
    /** For formatting of each cookie, see [Puppeteer setCookie docs](https://github.com/puppeteer/puppeteer/blob/v1.9.0/docs/api.md#pagesetcookiecookies) */
50
    cookies: Array<string>;
51
    /** Make Penthouse throw on errors parsing the original CSS. Legacy option, not recommended */
52
    strict: boolean;
53
    /**
54
     * Let Penthouse stop if the server response code is not matching this value. number and
55
     * regex types are tested against the [response.status()](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#responsestatus). A function is also allowed and
56
     * gets [Response](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#class-response) as argument. The function should return a boolean.
57
     */
58
    allowedResponseCode: number | RegExp | Function;
59
}
60
61
type DeclCallback = (node: object, value: string) => boolean;
62
63
interface CriticalConfig {
64
    /** Inline critical-path CSS using filamentgroup's loadCSS. Pass an object to configure `inline-critical` */
65
    inline: boolean;
66
    /** Base directory in which the source and destination are to be written */
67
    base: string;
68
    /** HTML source to be operated against. This option takes precedence over the `src` option */
69
    html: string;
70
    /** An array of paths to css files, file globs or Vinyl file objects. */
71
    css: Array<string>;
72
    /** Location of the HTML source to be operated against */
73
    src: string;
74
    /**
75
     * Location of where to save the output of an operation.
76
     * Use an object with 'html' and 'css' props if you want to store both
77
     */
78
    target: string | Partial<{
79
        css: string;
80
        html: string;
81
        uncritical: string;
82
    }>;
83
    /** Width of the target viewport */
84
    width: number;
85
    /** Height of the target viewport */
86
    height: number;
87
    /** Enable minification of generated critical-path */
88
    minify: boolean;
89
    /**
90
     * Remove the inlined styles from any stylesheets referenced in the HTML.
91
     * It generates new references based on extracted content so it's safe to use for
92
     * multiple HTML files referencing the same stylesheet. Use with caution.
93
     * Removing the critical CSS per page results in a unique async loaded CSS file for every page.
94
     * Meaning you can't rely on cache across multiple pages
95
     */
96
    extract: boolean;
97
    /** Inline images */
98
    inlineImages: boolean;
99
    /** List of directories/urls where the inliner should start looking for assets */
100
    assetPaths: Array<string>;
101
    /** Sets a max file size (in bytes) for base64 inlined images */
102
    maxImageFileSize: number;
103
    /**
104
     * Critical tries it's best to rebase the asset paths relative to the document.
105
     * If this doesn't work as expected you can always use this option to control the rebase paths.
106
     * See postcss-url for details. (https://github.com/pocketjoso/penthouse#usage-1).
107
     */
108
    rebase: object | Function;
109
    /** ignore CSS rules */
110
    ignore: Partial<{
111
        atrule: Array<string>;
112
        rule: Array<string>;
113
        decl: DeclCallback;
114
    }>;
115
    /** User agent to use when fetching a remote src */
116
    userAgent: string;
117
    /** Configuration options for `penthouse`. */
118
    penthouse: Partial<PenthouseConfig>;
119
    /** Configuration options for `got`. */
120
    request: object;
121
    /** RFC2617 basic authorization: `user` */
122
    user: string;
123
    /** RFC2617 basic authorization: `pass` */
124
    pass: string;
125
    /** Throw an error if no css is found */
126
    strict: boolean;
127
}
128
129
interface CriticalPages {
130
    /** Combined with `criticalUrl` to determine the URLs to scrape for Critical CSS */
131
    uri: string;
132
    /** Critical CSS files are named with the `template` path, and saved to the `criticalBase` directory */
133
    template: string;
134
}
135
136
interface CriticalPluginConfig {
137
    /**
138
     * The base URL to use in combination with the `criticalPages` `uri`s to determine the URLs to scrape for Critical CSS.
139
     * This can also be a file system path. This is combined with `criticalPages.uri`
140
     * to determine pages to scrap for critical CSS.
141
     * Determines the `criticalConfig.src` property
142
     */
143
    criticalUrl: string;
144
    /**
145
     * The base file system path to where the generated Critical CSS file should be saved.
146
     * This is combined with `criticalPages.template` with `_critical.min.css` appended
147
     * to it to determine the saved critical CSS file name.
148
     * Determines the `criticalConfig.target` property
149
     */
150
    criticalBase?: string;
151
    /**
152
     * An array objects that contain the page `uri`s that are combined with the `criticalUrl` to
153
     * determine the URLs to scrape for Critical CSS. The resulting files are named with the
154
     * `template` path, and saved to the `criticalBase` directory
155
     */
156
    criticalPages: Partial<CriticalPages>[];
157
    /**
158
     * This is the full [config for critical](https://github.com/addyosmani/critical#options) that is passed
159
     * through to the `critical` package.
160
     * You may optionally override any properties you like here
161
     */
162
    criticalConfig?: Partial<CriticalConfig>;
163
}
164
165
export { CriticalPages, CriticalPluginConfig };
166